﻿Type.registerNamespace("BM");

BM.ExtenderDuplicator = {
    findFunction: function(text) {
        var handlers = Sys.Application.get_events()._getEvent('init');
        for (var i = 0; i < handlers.length; i++) {
            var handlerText = handlers[i].toString();
            if (handlerText.indexOf(text) != -1) {
                return handlerText;
            }
        }
    },

    run: function(prototypeId, elementId, suffix) {
        var idToFind = suffix != null ? prototypeId + suffix : prototypeId;
        var functionText = BM.ExtenderDuplicator.findFunction(idToFind);
        if (functionText) {
            functionText = functionText.replace(new RegExp(prototypeId, 'g'), elementId);
            eval("var x = " + functionText + "; x();");
        }
    }
}